#pragma once

#include "tcp_connection.h"

namespace rr {
namespace nio {


class TcpClient : public std::enable_shared_from_this<TcpClient>
{
public:
    using Sptr = std::shared_ptr<TcpClient>;

    TcpClient(EventLoop::Sptr loop);
    ~TcpClient();

    void SetConnectionCallback(const ConnectionCallback& cb) { connection_cb_ = cb; }
    void SetCloseCallback(const CloseCallback& cb) { close_cb_ = cb; }

    int32_t Start(int32_t time_out_ms = 3000);
    void Stop();

private:
    void OnConnect(const boost::system::error_code& error);

private:
    EventLoop::Sptr loop_;
    boost::asio::ip::tcp::socket socket_;
    TcpConnection::Sptr conn_;
    ConnectionCallback connection_cb_ = nullptr;
    CloseCallback close_cb_ = nullptr;
    std::shared_ptr<boost::asio::steady_timer> timer_;
};

} //namespace 
} //namespace 